home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / EXEINFO.ZIP / EXE.DOC < prev    next >
Text File  |  1997-01-02  |  2KB  |  48 lines

  1. This file written 970102 by David Ashley (dash@netcom.com).
  2.  
  3. This program prints out the header of an EXE file.
  4.  
  5. When DOS loads a program it decides where in memory the program is going to
  6. be loaded. This means choosing the initial segment in memory. DOS examines
  7. the header to figure out how big the header itself is. The word at offset 8
  8. tells the # of 16 byte paragraphs the header contains. Usually this contains
  9. 20h, meaning there are 32 16 byte paragraphs for a total of 512 bytes (200hex).
  10.  
  11. Call the segment DOS initially loads the program ISEG.
  12.  
  13. The EXE file after the header gets loaded at segment ISEG+10h, at offset
  14. 0 (ISEG+10h:0). The number of bytes that will be loaded is determined by
  15. header words at offsets 4 and 2. Take the word at offset 4, subtract 1, then
  16. multiply by 512. Then add the word at offset 2. This is the total number of
  17. bytes to be loaded.
  18.  
  19. After loading, the file is relocated if necessary. The word at offset 6 tells
  20. the number of places that need to be relocated. The word at offset 18h tells
  21. where the relocation list is as an offset from the start of the header (which
  22. is also the start of the EXE file).
  23.  
  24. Each entry in the relocation list is a segment:offset pair. The location to
  25. patch is ISEG+10h+segment:offset. This points to a word that must be fixed.
  26. Dos fixes it by adding the value of ISEG+10h to the contents of the word and
  27. storing the result back into the word's location. That's all there is to it!
  28.  
  29. The program is ready to run in memory, all dos has to do is set up the
  30. registers and jump to it.
  31.  
  32. Dos sets up the DS,SS, SP (and I think ES) registers as follows:
  33. DS = ISEG
  34. ES = DS (it always seems to match ds)
  35. SS = ISEG + 10h + word at offset 0eh in the header
  36. SP = word at offset 10h in the header
  37.  
  38. Now we need to jump into the code. The location is determined by:
  39.  
  40. CS = ISEG + 10h + word at offset 16h in the header
  41. IP = word at offset 14h in the header
  42.  
  43. ---------------------------
  44. The EXE.C program contains the structure of the header.
  45.  
  46. Hope this helps.
  47. -Dave
  48.